import argparse
import numpy as np
from reader import BinReader
from writer import VTKWriter, MeshioWriter, VTKHDFWriter

# Example usage
if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Process vis file generation.")
    parser.add_argument("--case_dir", type=str, help="Case directory path")
    parser.add_argument("--case_name", type=str, help="Case name")
    parser.add_argument(
        "--output_path", type=str, default="output/", help="Output path"
    )
    args = parser.parse_args()

    reader = BinReader()
    reader.scan(f"{args.case_dir}{args.case_name}")

    if (reader.get_time_steps() == 0):
        print(f"No timesteps found in {args.case_dir}{args.case_name}, check if the case files are empty or corrupted.")
        exit(1)
    # reader.print_grid_info()
    # reader.print_grid_nums()
    # reader.print_static_props()
    # reader.print_dynamic_props()

    # Write vtk file
    # writer = VTKWriter(reader)
    # writer = MeshioWriter(reader)

    # writer.write_well(f"{args.output_path}{args.case_name}", args.case_name)
    # writer.write_poro(f"{args.output_path}{args.case_name}", args.case_name)
    # writer.write_all_timesteps(f"{args.output_path}{args.case_name}", args.case_name)
    # writer.write_all_timesteps_timeseries(f"{args.output_path}{args.case_name}", args.case_name)

    # Write vtk file with HDF5 (.vtkhdf file format)
    writer = VTKHDFWriter(reader)
    writer.write_timeseries_complete(f"{args.output_path}{args.case_name}", args.case_name)
